<?php
class TasksController extends DomController {
	
	public function tasks() {
		
		$source = new DomArDataSource( Task::query()->orderBy('t.id DESC'), 40 );
		
		function clientNameHandler( $row ) {
			return $row->client->username;	
		}
		
		function adminNameHandler( $row ) {
			return $row->admin->username;	
		}
		
		function statusHandler( $row ) {
			return $row->done ? '<b style="color:green;">Done</b>' : '<b style="color:orange;">Undone</b>';	
		}
		
		$panel = array(
			'title' => 'Tasks',
			'layout' => 'table',
			'layoutConfig' => array(
					'columns' => 1,
			),
			'items' => array(
				array(
					'type' => 'grid',
					'source' => $source,
					'fields' => array(
						array('handler' => 'adminNameHandler', 'title' => 'Admin'),
						array('handler' => 'clientNameHandler', 'title' => 'Client'),
						array('handler' => 'statusHandler', 'title' => 'Status'),
						array('type' => 'gridButton', 'value' => 'Do it', 'link' => $this->getSiteUrl('MeterReadings/meterReading/0/'), 'title' => 'Options','colspan' => 2),
					),
				),
			),
		);
		
		$this->view->contents = DomFg::render( $panel );
	}
	
}
	